import string
import random

from django.db import models


# Create your models here.
class Student(models.Model):
    name = models.CharField(max_length=20)

    age = models.IntegerField()

    sex = models.IntegerField(choices=((1, '男'), (2, '女')), default=1)

    card_no = models.CharField(max_length=18)

    @classmethod
    def insert_test_data(cls, num=100):
        def random_str(raw_ite, length):
            return ''.join(random.choices(raw_ite, k=length))

        obj_list = []
        for _ in range(num):
            obj_list.append(Student(
                name=random_str(string.ascii_lowercase, 8),
                age=random.randint(18, 50),
                sex=random.choice([1, 2]),
                card_no=random_str(string.digits, 18)
            ))

        Student.objects.bulk_create(obj_list)